<?
    GLOBAL $_GET;              
    require_once(SSPATH.'templates/chrome_plugin.php');
//    require_once(SSPATH.'templates/banners.php');
    $v = 3;
    if ($this->getVar('dev')) {    
        $flashFile = 'http://oformi-foto.ru/pj/dev/pj_mail.swf?v='.$v;
        $flashFree = 'http://oformi-foto.ru/pj/dev/pj_free.swf?v='.$v;
        $v = rand(1, 1000000);
    } else {  
        $flashFile = 'http://oformi-foto.ru/pj/v15/pj_mail.swf?v='.$v;
        $flashFree = 'http://oformi-foto.ru/pj/v15/pj_free.swf?v='.$v;
/*        
        $flashFile = 'http://cdn8.appsmail.ru/hosting/441207/pj_mail.swf?v='.$v;
        $flashFree = 'http://cdn1.appsmail.ru/hosting/441207/pj_free.swf?v='.$v;
*/        
    }     
    
    $fparams = array('state', 'sid', 'tid', 'gid', 'dev', 'imageProxy');
    
    $_GET['imageProxy'] = 'http://vmaya.ru/getimage.php?src='
?>
<div id="flashAPP" style="width:100%;">
    <div id="embed" style="width:100%;"></div>
<script type="text/javascript">
    var app_params = {
        app_id: '',
        viewer_id: 0,
        dev: <?=$this->request->getVar('dev', 0)?>,
        plugins: '<?=$plugins['free']?>',
        ver: <?=$ver?>
<?
    foreach ($fparams as $pName)
    if (isset($_GET[$pName]))
        echo ",\n{$pName}:'".$_GET[$pName]."'";
?>
    };
    function appInit(sfwFile, aliase, params) {
        var str_params = '';
        for (var index in params)
            str_params += (str_params?'&':'') + index + '=' + params[index];
        
        var flashAPP = $('flashAPP'); 
        var size = flashAPP.getSize();
        $('social').setStyle('width', size.x);
        
//        var size = $('flashAPP').getSize();
        var app = new SWFObject(sfwFile, aliase, size.x, 880, "9");
        app.addParam("movie", sfwFile);
        app.addParam("quality", "high");
        app.addParam("scale", "noscale");
        app.addParam("menu", "false");
        app.addParam("align", "middle");
        app.addParam("salign", "tl");
        
        app.addParam("base", "<?=$basePath?>");
        app.addParam("wmode", "transparent");
        app.addParam("allowNetworking", "all");
        app.addParam("allowFullScreen", "true");   
        app.addParam("allowScriptAccess", "always");
        app.addParam("FlashVars", str_params);
        app.write("embed");
    }
    
    function reload() {
        document.location.href = document.location.href;
    }
    
    function freeInit() {
        app_params.app_id = 'pj_free';
        appInit('<?=$flashFree?>', 'pj_free', app_params);
    }
    
/*    function checkLoginStatus(result) {
        if (result.is_app_user != 1) freeInit();
        else {
            mailru.common.users.getInfo(function(result){
                mailru.session.ver = app_params.ver;
                <?=(($isdev)?'mailru.session.dev = 1;':'')?>
                <? 
                if (isset($_GET['state']) && (@$_GET['source'] != 'mail')) {
                ?>
                    appInit('pj_free.swf', 'pj_free', app_params);
                <?
                } else {
                    if (@$_GET['source'] == 'mail') {
                        ?>
                            mailru.session.state='<?=$_GET['state']?>';
                        <?
                    }
                ?>
                    appInit('pj_mail.swf', 'mail_pj', mailru.session);
                <?
                }
                ?>
            });
        }
    }*/
    
    window.addEvent('login_status', function(e) {
        if (e.source == 'mm') {
            if (e.status) {
                app_params = $merge(app_params, mailru.session);
                app_params.plugins = '<?=$plugins['mail']?>';
                <? 
                if (isset($_GET['state']) && (@$_GET['source'] != 'mail')) {
                ?>
                    appInit('<?=$flashFree?>', 'pj_free', app_params);
                <?
                } else {
                    if (@$_GET['source'] == 'mail') {
                        ?>
                            app_params.state='<?=$_GET['state']?>';
                        <?
                    }
                ?>
                    appInit('<?=$flashFile?>', 'mail_pj', app_params);
                <?
                }
                ?>
            } else freeInit();
        }
    });
    
    var flashAPP = $('flashAPP'); 
    flashAPP.getParent().setStyle('width', '100%');
    
    var size = flashAPP.getSize();
    if (size.x < 500) size.x = 500;
    else if (size.x > 1500) size.x = 1500;
    flashAPP.setStyle('width', size.x);
</script>
<?
    include(dirname(__FILE__).'/social.html');
?>
</div>